<?php 
class pay_admin 
{ 
	function admin_pay_list() 
	{ 
		global $mysql_conn,$v_file;
		$list_page = $_GET['list_page'];
		$list_num = $_GET['list_num'];
		$sousuokey = $_GET['sousuokey'];
		if (empty($list_page)) $list_page = 1;
		if (empty($list_num)) $list_num = 10;
		if ($list_page < 5) {$list_page0 = 1;} else {$list_page0 = $list_page-4;}
		if ($list_page < 5) {$list_page1 = 1;} else {$list_page1 = $list_page-3;}
		if ($list_page < 5) {$list_page2 = 2;} else {$list_page2 = $list_page-2;}
		if ($list_page < 5) {$list_page3 = 3;} else {$list_page3 = $list_page-1;}
		if ($list_page < 5) {$list_page4 = 4;} else {$list_page4 = $list_page;}
		if ($list_page < 5) {$list_page5 = 5;} else {$list_page5 = $list_page+1;}
		if ($list_page < 5) {$list_page6 = 6;} else {$list_page6 = $list_page+2;}
		if ($list_page < 5) {$list_page7 = 7;} else {$list_page7 = $list_page+3;}
		if ($list_page < 5) {$list_page8 = 8;} else {$list_page8 = $list_page+4;}
		$page_btn .= "<button type='button' class='btn btn-white' onClick='list_page_go(".$list_page0.")'><i class='fa fa-chevron-left'></i></button>";
		$page_btn .= "<button class='btn btn-white' id='list_page".$list_page1."' onClick='list_page_go(".$list_page1.")'>".$list_page1."</button>";
		$page_btn .= "<button class='btn btn-white' id='list_page".$list_page2."' onClick='list_page_go(".$list_page2.")'>".$list_page2."</button>";
		$page_btn .= "<button class='btn btn-white' id='list_page".$list_page3."' onClick='list_page_go(".$list_page3.")'>".$list_page3."</button>";
		$page_btn .= "<button class='btn btn-white' id='list_page".$list_page4."' onClick='list_page_go(".$list_page4.")'>".$list_page4."</button>";
		$page_btn .= "<button class='btn btn-white' id='list_page".$list_page5."' onClick='list_page_go(".$list_page5.")'>".$list_page5."</button>";
		$page_btn .= "<button class='btn btn-white' id='list_page".$list_page6."' onClick='list_page_go(".$list_page6.")'>".$list_page6."</button>";
		$page_btn .= "<button class='btn btn-white' id='list_page".$list_page7."' onClick='list_page_go(".$list_page7.")'>".$list_page7."</button>";
		$page_btn .= "<button type='button' class='btn btn-white' onClick='list_page_go(".$list_page8.")'><i class='fa fa-chevron-right'></i></button>";
		$list_limit = ($list_page-1)*$list_num.",".$list_num;
		if (empty($sousuokey)) {
			$sql = "SELECT * from `pay` limit ".$list_limit;
		} else {
			$sql = "SELECT * from `pay` WHERE `pay_sn` = '".$sousuokey."'";
		}
		$result = mysql_query($sql,$mysql_conn);
		while(@$row=mysql_fetch_array($result)) {
			$pay_id = $row['pay_id'];
			$pay_user = $row['pay_user'];
			$pay_sn = $row['pay_sn'];
			$pay_money = $row['pay_money'];
			$pay_state = $row['pay_state'];
			$serverlist .= "<tr><td>";
			$serverlist .= "    <input type='checkbox' class='i-checks' name='input[]'>";
			$serverlist .= "</td>";
			$serverlist .= "<td>".$pay_id."</td>";
			$serverlist .= "<td>".$pay_user."</td>";
			$serverlist .= "<td>".$pay_sn."</td>";
			$serverlist .= "<td>".$pay_money."</td>";
			if ($pay_state == "1") {
				$serverlist .= "<td> 已审核 </td>";
				$serverlist .= "<td>";
			} else if ($pay_state == "2") {
				$serverlist .= "<td> 已拒绝 </td>";
				$serverlist .= "<td>";
			} else {
				$serverlist .= "<td> 未处理 </td>";
				$serverlist .= "<td>";
				$serverlist .= "<a href='#' class='btn btn-white btn-xs' onClick='admin_pay_ok(".$pay_id.");'><i class='fa fa-edit'></i> 审核 </a>";
				$serverlist .= "<a href='#' class='btn btn-white btn-xs' onClick='admin_pay_no(".$pay_id.");'><i class='fa fa-edit'></i> 拒绝 </a>";
			}
			$serverlist .= "<a href='#' class='btn btn-white btn-xs' onClick='admin_pay_del(".$pay_id.");'><i class='fa fa-trash-o'></i> 删除 </a>";
			$serverlist .= "</td></tr>";
		}
		require($v_file);
	}
	function admin_pay_ok() 
	{ 
		global $mysql_conn;
		$pay_id = $_POST['pay_id'];
		$user_name = $_COOKIE['user_name'];
		$sql = "SELECT * from `pay` WHERE `pay_id` = '".$pay_id."'";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		$pay_user = $row['pay_user'];
		$pay_sn = $row['pay_sn'];
		$pay_money = $row['pay_money'];
		$sql = "SELECT * from `web` WHERE `web_isset` = '1'";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		$web_glod = $row['web_glod'];
		$pay_glod = $web_glod*$pay_money;
		$sql = "SELECT * from `user` WHERE `user_name` = '".$pay_user."'";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		$user_glod = $row['user_glod'];
		$user_glod_now = $user_glod+$pay_glod;
		$sql = "UPDATE `pay` SET `pay_state` = '1' WHERE `pay_id` =".$pay_id.";";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		$sql = "UPDATE `user` SET `user_glod` = '".$user_glod_now."' WHERE `user_name` ='".$pay_user."';";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		$log_title = "管理员：".$user_name." 成功审核用户：".$pay_user." 编号为：".$pay_sn." 的订单，向其账户充值：RMB ".$pay_money." 元，折合：".$pay_glod." 金币。";
		$sql="INSERT INTO pay_log (log_id, log_user, log_title, log_type, log_glod) VALUES (NULL,'$pay_user','$log_title','充值','$pay_glod')";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		echo "2";
	}
	function admin_pay_no() 
	{ 
		global $mysql_conn,$v_file;
		$pay_id = $_GET['pay_id'];
		require($v_file);
	}
	function admin_pay_no_do() 
	{ 
		global $mysql_conn;
		$pay_id = $_POST['pay_id'];
		$pay_liyou = $_POST['pay_liyou'];
		$user_name = $_COOKIE['user_name'];
		$sql = "SELECT * from `pay` WHERE `pay_id` = '".$pay_id."'";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		$pay_user = $row['pay_user'];
		$pay_sn = $row['pay_sn'];
		$pay_money = $row['pay_money'];
		$sql = "SELECT * from `web` WHERE `web_isset` = '1'";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		$web_glod = $row['web_glod'];
		$pay_glod = $web_glod*$pay_money;
		$sql = "UPDATE `pay` SET `pay_state` = '2' WHERE `pay_id` =".$pay_id.";";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		$log_title = "管理员：".$user_name." 拒绝用户：".$pay_user." 编号为：".$pay_sn." 的订单，订单价值：RMB ".$pay_money." 元，折合：".$pay_glod." 金币。拒绝理由：".$pay_liyou;
		$sql="INSERT INTO pay_log (log_id, log_user, log_title, log_type, log_glod) VALUES (NULL,'$user_name','$log_title','通知','0')";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		echo "2";
	}
	function admin_pay_del_do() 
	{ 
		global $mysql_conn;
		$pay_id = $_POST['pay_id'];
		$sql = "DELETE from `pay` WHERE `pay_id` = '".$pay_id."'";
		$result = mysql_query($sql,$mysql_conn);
		@$row = mysql_fetch_array($result);
		echo "2";
	}
	function admin_pay_log() 
	{ 
		global $mysql_conn,$v_file;
		$list_page = $_GET['list_page'];
		$list_num = $_GET['list_num'];
		$sousuokey = $_GET['sousuokey'];
		if (empty($list_page)) $list_page = 1;
		if (empty($list_num)) $list_num = 10;
		if ($list_page < 5) {$list_page0 = 1;} else {$list_page0 = $list_page-4;}
		if ($list_page < 5) {$list_page1 = 1;} else {$list_page1 = $list_page-3;}
		if ($list_page < 5) {$list_page2 = 2;} else {$list_page2 = $list_page-2;}
		if ($list_page < 5) {$list_page3 = 3;} else {$list_page3 = $list_page-1;}
		if ($list_page < 5) {$list_page4 = 4;} else {$list_page4 = $list_page;}
		if ($list_page < 5) {$list_page5 = 5;} else {$list_page5 = $list_page+1;}
		if ($list_page < 5) {$list_page6 = 6;} else {$list_page6 = $list_page+2;}
		if ($list_page < 5) {$list_page7 = 7;} else {$list_page7 = $list_page+3;}
		if ($list_page < 5) {$list_page8 = 8;} else {$list_page8 = $list_page+4;}
		$page_btn .= "<button type='button' class='btn btn-white' onClick='list_page_go(".$list_page0.")'><i class='fa fa-chevron-left'></i></button>";
		$page_btn .= "<button class='btn btn-white' id='list_page".$list_page1."' onClick='list_page_go(".$list_page1.")'>".$list_page1."</button>";
		$page_btn .= "<button class='btn btn-white' id='list_page".$list_page2."' onClick='list_page_go(".$list_page2.")'>".$list_page2."</button>";
		$page_btn .= "<button class='btn btn-white' id='list_page".$list_page3."' onClick='list_page_go(".$list_page3.")'>".$list_page3."</button>";
		$page_btn .= "<button class='btn btn-white' id='list_page".$list_page4."' onClick='list_page_go(".$list_page4.")'>".$list_page4."</button>";
		$page_btn .= "<button class='btn btn-white' id='list_page".$list_page5."' onClick='list_page_go(".$list_page5.")'>".$list_page5."</button>";
		$page_btn .= "<button class='btn btn-white' id='list_page".$list_page6."' onClick='list_page_go(".$list_page6.")'>".$list_page6."</button>";
		$page_btn .= "<button class='btn btn-white' id='list_page".$list_page7."' onClick='list_page_go(".$list_page7.")'>".$list_page7."</button>";
		$page_btn .= "<button type='button' class='btn btn-white' onClick='list_page_go(".$list_page8.")'><i class='fa fa-chevron-right'></i></button>";
		$list_limit = ($list_page-1)*$list_num.",".$list_num;
		if (empty($sousuokey)) {
			$sql = "SELECT * from `pay_log` limit ".$list_limit;
		} else {
			$sql = "SELECT * from `pay_log` WHERE `log_user` = '".$sousuokey."'";
		}
		$result = mysql_query($sql,$mysql_conn);
		while(@$row=mysql_fetch_array($result)) {
			$log_id = $row['log_id'];
			$log_user = $row['log_user'];
			$log_title = $row['log_title'];
			$log_type = $row['log_type'];
			$log_glod = $row['log_glod'];
			$serverlist .= "<tr><td>";
			$serverlist .= "    <input type='checkbox' class='i-checks' name='input[]'>";
			$serverlist .= "</td>";
			$serverlist .= "<td>".$log_id."</td>";
			$serverlist .= "<td>".$log_user."</td>";
			$serverlist .= "<td>".$log_title."</td>";
			$serverlist .= "<td>".$log_type."</td>";
			$serverlist .= "<td>".$log_glod."</td>";
			$serverlist .= "</tr>";
		}
		require($v_file);
	}
} 
/* End of file democontroller.php */ 